{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 梯度下降法模拟"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1.  , -0.95, -0.9 , -0.85, -0.8 , -0.75, -0.7 , -0.65, -0.6 ,\n",
       "       -0.55, -0.5 , -0.45, -0.4 , -0.35, -0.3 , -0.25, -0.2 , -0.15,\n",
       "       -0.1 , -0.05,  0.  ,  0.05,  0.1 ,  0.15,  0.2 ,  0.25,  0.3 ,\n",
       "        0.35,  0.4 ,  0.45,  0.5 ,  0.55,  0.6 ,  0.65,  0.7 ,  0.75,\n",
       "        0.8 ,  0.85,  0.9 ,  0.95,  1.  ,  1.05,  1.1 ,  1.15,  1.2 ,\n",
       "        1.25,  1.3 ,  1.35,  1.4 ,  1.45,  1.5 ,  1.55,  1.6 ,  1.65,\n",
       "        1.7 ,  1.75,  1.8 ,  1.85,  1.9 ,  1.95,  2.  ,  2.05,  2.1 ,\n",
       "        2.15,  2.2 ,  2.25,  2.3 ,  2.35,  2.4 ,  2.45,  2.5 ,  2.55,\n",
       "        2.6 ,  2.65,  2.7 ,  2.75,  2.8 ,  2.85,  2.9 ,  2.95,  3.  ,\n",
       "        3.05,  3.1 ,  3.15,  3.2 ,  3.25,  3.3 ,  3.35,  3.4 ,  3.45,\n",
       "        3.5 ,  3.55,  3.6 ,  3.65,  3.7 ,  3.75,  3.8 ,  3.85,  3.9 ,\n",
       "        3.95,  4.  ,  4.05,  4.1 ,  4.15,  4.2 ,  4.25,  4.3 ,  4.35,\n",
       "        4.4 ,  4.45,  4.5 ,  4.55,  4.6 ,  4.65,  4.7 ,  4.75,  4.8 ,\n",
       "        4.85,  4.9 ,  4.95,  5.  ,  5.05,  5.1 ,  5.15,  5.2 ,  5.25,\n",
       "        5.3 ,  5.35,  5.4 ,  5.45,  5.5 ,  5.55,  5.6 ,  5.65,  5.7 ,\n",
       "        5.75,  5.8 ,  5.85,  5.9 ,  5.95,  6.  ])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_x = np.linspace(-1,6,141)\n",
    "plot_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11.25  , 10.9025, 10.56  , 10.2225,  9.89  ,  9.5625,  9.24  ,\n",
       "        8.9225,  8.61  ,  8.3025,  8.    ,  7.7025,  7.41  ,  7.1225,\n",
       "        6.84  ,  6.5625,  6.29  ,  6.0225,  5.76  ,  5.5025,  5.25  ,\n",
       "        5.0025,  4.76  ,  4.5225,  4.29  ,  4.0625,  3.84  ,  3.6225,\n",
       "        3.41  ,  3.2025,  3.    ,  2.8025,  2.61  ,  2.4225,  2.24  ,\n",
       "        2.0625,  1.89  ,  1.7225,  1.56  ,  1.4025,  1.25  ,  1.1025,\n",
       "        0.96  ,  0.8225,  0.69  ,  0.5625,  0.44  ,  0.3225,  0.21  ,\n",
       "        0.1025,  0.    , -0.0975, -0.19  , -0.2775, -0.36  , -0.4375,\n",
       "       -0.51  , -0.5775, -0.64  , -0.6975, -0.75  , -0.7975, -0.84  ,\n",
       "       -0.8775, -0.91  , -0.9375, -0.96  , -0.9775, -0.99  , -0.9975,\n",
       "       -1.    , -0.9975, -0.99  , -0.9775, -0.96  , -0.9375, -0.91  ,\n",
       "       -0.8775, -0.84  , -0.7975, -0.75  , -0.6975, -0.64  , -0.5775,\n",
       "       -0.51  , -0.4375, -0.36  , -0.2775, -0.19  , -0.0975,  0.    ,\n",
       "        0.1025,  0.21  ,  0.3225,  0.44  ,  0.5625,  0.69  ,  0.8225,\n",
       "        0.96  ,  1.1025,  1.25  ,  1.4025,  1.56  ,  1.7225,  1.89  ,\n",
       "        2.0625,  2.24  ,  2.4225,  2.61  ,  2.8025,  3.    ,  3.2025,\n",
       "        3.41  ,  3.6225,  3.84  ,  4.0625,  4.29  ,  4.5225,  4.76  ,\n",
       "        5.0025,  5.25  ,  5.5025,  5.76  ,  6.0225,  6.29  ,  6.5625,\n",
       "        6.84  ,  7.1225,  7.41  ,  7.7025,  8.    ,  8.3025,  8.61  ,\n",
       "        8.9225,  9.24  ,  9.5625,  9.89  , 10.2225, 10.56  , 10.9025,\n",
       "       11.25  ])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot_y = (plot_x-2.5)**2-1\n",
    "plot_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deVyVZd7H8c+PHRRQZBFkVXBX1Mi90rQstZyapmxxqmmbmpbpaeppmn2reWamZ9qbaXfKtDQrK1vNyswNNVdQAdkREBWQ/Ryu5w9wHsdc4cB97nN+79eLl0B07m9IXy+v+7quW4wxKKWUsh8fqwMopZTqGC1wpZSyKS1wpZSyKS1wpZSyKS1wpZSyKb/uvFhkZKRJTk7uzksqpZTtbdy4cb8xJurYz3drgScnJ5OZmdmdl1RKKdsTkYLjfV6nUJRSyqa0wJVSyqa0wJVSyqa0wJVSyqa0wJVSyqa0wJVSyqa0wJVSyqZsUeAfbC1jwbrjLoNUSim3VnKogT9/mE1FbaPLX9sWBb58Wxl/+3gXTQ6n1VGUUuqMvLGhiH9+lUuzo9Xlr22LAr/q7AQO1rfw8Y5yq6MopdRpc7YaFmcWcU5aFPG9Q1z++r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ppOYBMwDzm9fOvZt+4jRXcUCK0VkK21/sH9qjHH75Xk2EQN8LSJbgPXAB8aYjyzOdDJ3AQvafxZGAQ+76oV1K71SStmUrUbgSiml/p8WuFJK2ZQWuFJK2ZQWuFJK2ZQWuFJK2ZQWuFJK2ZQWuFJK2dT/AVD0ZJtHFzaDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#绘制x,y曲线\n",
    "plt.plot(plot_x,plot_y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#求导\n",
    "def dJ(theta):\n",
    "    return 2*(theta-2.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#损失函数\n",
    "def J(theta):\n",
    "    try:\n",
    "        return (theta-2.5)**2-1.\n",
    "    except:\n",
    "        return float(\"inf\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.499891109642585\n",
      "-0.99999998814289\n"
     ]
    }
   ],
   "source": [
    "#梯度下降法\n",
    "eta = 0.1  #学习率\n",
    "epsilon = 1e-8 #精度\n",
    "theta = 0.0  #起始点\n",
    "while True:\n",
    "    gradient = dJ(theta)\n",
    "    last_theta = theta\n",
    "    theta = theta - eta * gradient\n",
    "    \n",
    "    if(abs(J(theta) - J(last_theta)) < epsilon):\n",
    "        break\n",
    "\n",
    "print(theta)\n",
    "print(J(theta))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxI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R+9RLSItRWSWiGyq/fs72F3v7agCB9YDVwMLbQc5HhHxB14ALgZ6AmNFpKfdVCf1FnCR7RB15AIeNMb0AFKAez38Z1sOjDDG9AX6AReJSIrlTKfyAJBuO8RpOM8Y088Ba8GfAb4wxnQH+uLGn7GjCtwYk26M2Ww7x0kMBLYZYzKMMRXAdOAKy5lOyBizENhvO0ddGGN2GWNW1X5dTM1/BO3spjoxU6Ok9mFg7YfHrhgQkXjgUmCK7SzeRETCgXOA1wGMMRXGmIPuen9HFbgDtAOyj3qcgweXjFOJSCJwJvCD3SQnVzslsQbYA3xtjPHkvE8DDwPVtoPUkQG+EpGVIjLBdpiT6AgUAG/WTk9NEZHm7npzjytwEflGRNYf58NjR7JHOd5dcz121OVEItIC+ACYaIwpsp3nZIwxVcaYfkA8MFBEetvOdDwiMhrYY4xZaTvLaRhqjOlPzXTlvSJyju1AJxAA9AdeMsacCRwC3HZuzONuqWaMGWk7QwPkAAlHPY4H8ixl8ToiEkhNeU8zxsy2naeujDEHRWQBNecbPPGE8VDgchG5BAgBwkVkqjHmJsu5TsgYk1f7eY+IfEjN9KUnnhvLAXKO+r+vWbixwD1uBO5wK4AuIpIkIkHAGGCO5UxeQUSEmnnEdGPMv23nORURiRKRlrVfhwIjgU12Ux2fMeYRY0y8MSaRmr+z33pyeYtIcxEJO/I1cCGe+YsRY8xuIFtEutU+dT6w0V3v76gCF5GrRCQHGAx8JiJf2s50NGOMC7gP+JKak2zvG2M22E11YiLyHrAU6CYiOSJyh+1MJzEUuBkYUbt0bE3tiNFTxQLzReRHan6xf22M8fjleQ4RAywWkbXAcuAzY8wXljOdzP3AtNq/C/2Ax931xnopvVJKOZSjRuBKKaX+RwtcKaUcSgtcKaUcSgtcKaUcSgtcKaUcSgtcKaUcSgtcKaUc6v8D5CZFc9PUMtAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#将上述梯度下降法可视化\n",
    "eta = 0.1  #学习率\n",
    "epsilon = 1e-8 #精度\n",
    "theta = 0.0  #起始点\n",
    "theta_history = [theta]\n",
    "while True:\n",
    "    gradient = dJ(theta)\n",
    "    last_theta = theta\n",
    "    theta = theta - eta * gradient\n",
    "    theta_history.append(theta)\n",
    "    \n",
    "    if(abs(J(theta) - J(last_theta)) < epsilon):\n",
    "        break\n",
    "        \n",
    "        \n",
    "plt.plot(plot_x,J(plot_x))\n",
    "plt.plot(np.array(theta_history),J(np.array(theta_history)),color='r',marker= \"+\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 封装梯度下降法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def gradient_descent(initial_theta,eta,n_iters=1e4,epsilon=1e-8):\n",
    "    theta = initial_theta\n",
    "    theta_history.append(initial_theta)\n",
    "    i_iter = 0\n",
    "    \n",
    "    while i_iter < n_iters:\n",
    "        gradient = dJ(theta)\n",
    "        last_theta = theta\n",
    "        theta = theta - eta * gradient\n",
    "        theta_history.append(theta)\n",
    "        \n",
    "        if(abs(J(theta) - J(last_theta)) < epsilon):\n",
    "            break\n",
    "            \n",
    "        i_iter += 1\n",
    "        \n",
    "def plot_theta_history():\n",
    "    plt.plot(plot_x,J(plot_x))\n",
    "    plt.plot(np.array(theta_history),J(np.array(theta_history)),color='r',marker=\"+\")\n",
    "    plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAA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AAgv8XrAhi4ZMxKRFIATAKwU2+SjjmmJPYBKAXwhVLKyHlfAvAUAJvuIF2kAHwuIpki8rDuMB0YDKAMwFuO6ak3RKS3q97ccAUuIl+KyKE2Pgw7km2hrUeWG3bUZUYiEgbgfQC/UEpV6s7TEaWUVSk1EUAigCkiMlZ3praIyE0ASpVSmbqzdMNMpdRk2KcrfyYis3QHakcAgMkAXlNKTQJQA8Bl18YM90g1pdQ83RmcUAAgqcXrRABFmrJ4HREJhL28Vyml1uvO01VKqQsikg779QYjXjCeCWChiNwIIARAhIisVErdqzlXu5RSRY5fS0XkX7BPXxrx2lgBgIIW//e1Di4scMONwE1uN4BhIjJIRIIALALwkeZMXkFEBPZ5xCyl1J905+mMiMSISJTj81AA8wAc1ZuqbUqp3yilEpVSKbD/mf3KyOUtIr1FJLz5cwDfgTH/YYRSqhhAvoiMcByaC+CIq97fVAUuIreKSAGA6QA+FpENujO1pJSyAHgUwAbYL7K9p5Q6rDdV+0TkXQDbAYwQkQIReVB3pg7MBHAfgGsdS8f2OUaMRhUPYJOIHID9H/YvlFKGX55nEnEAvhGR/QB2AfhYKfWZ5kwd+TmAVY4/CxMBPOeqN+at9EREJmWqETgREV3EAiciMikWOBGRSbHAiYhMigVORGRSLHAiIpNigRMRmdT/B2XUUsOYhEN1AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "eta = 0.01\n",
    "theta_history = []\n",
    "gradient_descent(0.0,eta)\n",
    "plot_theta_history()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9u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      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "eta = 1.1\n",
    "theta_history = []\n",
    "gradient_descent(0.0,eta,n_iters=10)\n",
    "plot_theta_history()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 在线性回归模型中使用梯度下降法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(666)\n",
    "x = 2 * np.random.random(size=100)\n",
    "y = x * 3. + 4. + np.random.normal(size=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 1)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = x.reshape(-1,1)\n",
    "X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100,)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAZmElEQVR4nO3df4wcZ33H8c839kHOgcZOfbTJgbEjIUdEaeNwqiBGlCSAQyDEDZUANRLQIIv+QASoK0eRSKhUxVIqkVatWrk0BQQKzq+6gUCTF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5STdZWZ7zWxLA+15g5ntN7OvmdmZ0bbG95eZrVAvCN4a21zLvrJeWneDpPsG7qr08+XDFXksYdtgbWPaY7I8t6jMv9vMLpM0I+n3Y5vXOOcOmdnpknab2QHn3PdrateXJd3onPu1mX1YvbOX8zM+t6o29b1X0i3OuaOxbVXtqyya+GxlZmbnqRfA3xjbvDHaX6+QdLeZPRz1UuvwHfXW5fiVmV0kaZek18iP/XWxpHudc/HeeuX7ysxept5B4wrn3C8H7054SmmfLx964E9KelXs51dKOpT2GDNbLulk9U6psjy3ynbJzN4i6SpJ73LO/bq/3Tl3KPr/MUnfUO/oXEu7nHM/i7XlnyW9Lutzq2pTzHs1cIpb4b7KIq3tVX62MjGz35H0GUmXOOd+1t8e219PSfo3lZc2HMk590vn3K+i21+VNGFmq+XB/tLwz1Yl+8rMJtQL3l90zt2W8JBqP19VJPdzDgQsVy+Bv04vDn6cOfCYP9PSQcybottnaukg5mMqbxAzS7s2qDdw85qB7askvTS6vVrSIypvQCdLu06N3f4DSXvciwMnj0ftWxXdPqWONkWPW6/eoJLVsa9ir7FW6YNy79DSQaZvV7mvcrRrjXpjOucObD9J0stjt78l6cIa2/Xb/fdPvWD4RLTvMn0GqmhTdH+/U3dSXfsq+rs/L+n6IY+p9PNV2ps+5o64SL0R3O9Luira9lfq9Wol6URJN0cf6G9LOj323Kui5x2U9Paa2/Wfkn4iaV/07/Zo+7mSDkQf4gOSLq+5XddKejB6/XsknRF77h9H+/FRSR+sq03Rz9dI2j7wvKr31Y2SfixpUb1ez+WSPizpw9H9JukfonYfkDRT9b7K2K7PSHo69tmajbafHu2r/dF7fFXN7frz2Gdrj2IHmKTPQB1tih7zAfUKGuLPq3pfvVG9tMf9sffpojo/X0ylB4BA+ZADBwAUQAAHgEARwAEgUARwAAgUARwAAkUAB4BAEcABIFD/DxzfJkrOEXIWAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X,y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用梯度下降法训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def J(theta, X_b, y):\n",
    "    try: \n",
    "        return np.sum((y - X_b.dot(theta))**2) / len(X_b)\n",
    "    except:\n",
    "        return float(\"inf\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def dJ(theta, X_b, y):\n",
    "    res = np.empty(len(theta))\n",
    "    res[0] = np.sum(X_b.dot(theta) - y)\n",
    "    for i in range(1,len(theta)):\n",
    "        res[i] = (X_b.dot(theta) - y).dot(X_b[:,i]) \n",
    "    \n",
    "    return res * 2 / len(X_b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "def gradient_descent(X_b, y, initial_theta, eta, n_iters=1e4, epsilon=1e-8):\n",
    "    theta = initial_theta\n",
    "    i_iter = 0\n",
    "    \n",
    "    while i_iter < n_iters: \n",
    "        gradient = dJ(theta, X_b, y)\n",
    "        last_theta = theta\n",
    "        theta = theta - eta * gradient\n",
    "        \n",
    "        if(abs(J(theta, X_b, y) - J(last_theta, X_b, y)) < epsilon):\n",
    "            break\n",
    "            \n",
    "        i_iter += 1\n",
    "        \n",
    "    return theta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_b = np.hstack([np.ones((len(X),1)), X])\n",
    "initial_theta = np.zeros(X_b.shape[1])\n",
    "eta = 0.01\n",
    "\n",
    "theta = gradient_descent(X_b, y, initial_theta, eta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.02145786, 3.00706277])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "theta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 封装我们的线性回归算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(666)\n",
    "x = 2 * np.random.random(size=100)\n",
    "y = x * 3. + 4. + np.random.normal(size=100)\n",
    "X = x.reshape(-1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from encapsulations.LinearRegression import LinearRegression\n",
    "lin_reg = LinearRegression()\n",
    "lin_reg.fit_gd(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3.00517934])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.023690891597359"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg.intercept_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 线性回归法使用向量化和数据标准化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 梯度下降法的向量化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "boston = datasets.load_boston()\n",
    "X = boston.data\n",
    "y = boston.target\n",
    "\n",
    "X = X[y < 50.0]\n",
    "y = y[y < 50.0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from encapsulations.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, seed=666)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用fit_normal方法拟合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 14.3 ms, sys: 3.05 ms, total: 17.4 ms\n",
      "Wall time: 7.39 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.8129794056212895"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from encapsulations.LinearRegression import LinearRegression\n",
    "lin_reg = LinearRegression()\n",
    "%time lin_reg.fit_normal(X_train, y_train)\n",
    "lin_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用梯度下降法拟合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "lin_reg2 = LinearRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/birch/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:90: RuntimeWarning: overflow encountered in reduce\n",
      "  return ufunc.reduce(obj, axis, dtype, out, **passkwargs)\n",
      "/home/birch/yuboML/encapsulations/LinearRegression.py:33: RuntimeWarning: overflow encountered in square\n",
      "  return np.sum((y - X_b.dot(theta) ** 2)) /len(y)\n",
      "/home/birch/yuboML/encapsulations/LinearRegression.py:56: RuntimeWarning: invalid value encountered in double_scalars\n",
      "  if (abs(J(theta, X_b, y) - J(last_theta, X_b, y)) < epsilon):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg2.fit_gd(X_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg2.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.42362e+01, 0.00000e+00, 1.81000e+01, 0.00000e+00, 6.93000e-01,\n",
       "        6.34300e+00, 1.00000e+02, 1.57410e+00, 2.40000e+01, 6.66000e+02,\n",
       "        2.02000e+01, 3.96900e+02, 2.03200e+01],\n",
       "       [3.67822e+00, 0.00000e+00, 1.81000e+01, 0.00000e+00, 7.70000e-01,\n",
       "        5.36200e+00, 9.62000e+01, 2.10360e+00, 2.40000e+01, 6.66000e+02,\n",
       "        2.02000e+01, 3.80790e+02, 1.01900e+01],\n",
       "       [1.04690e-01, 4.00000e+01, 6.41000e+00, 1.00000e+00, 4.47000e-01,\n",
       "        7.26700e+00, 4.90000e+01, 4.78720e+00, 4.00000e+00, 2.54000e+02,\n",
       "        1.76000e+01, 3.89250e+02, 6.05000e+00],\n",
       "       [1.15172e+00, 0.00000e+00, 8.14000e+00, 0.00000e+00, 5.38000e-01,\n",
       "        5.70100e+00, 9.50000e+01, 3.78720e+00, 4.00000e+00, 3.07000e+02,\n",
       "        2.10000e+01, 3.58770e+02, 1.83500e+01],\n",
       "       [6.58800e-02, 0.00000e+00, 2.46000e+00, 0.00000e+00, 4.88000e-01,\n",
       "        7.76500e+00, 8.33000e+01, 2.74100e+00, 3.00000e+00, 1.93000e+02,\n",
       "        1.78000e+01, 3.95560e+02, 7.56000e+00],\n",
       "       [2.49800e-02, 0.00000e+00, 1.89000e+00, 0.00000e+00, 5.18000e-01,\n",
       "        6.54000e+00, 5.97000e+01, 6.26690e+00, 1.00000e+00, 4.22000e+02,\n",
       "        1.59000e+01, 3.89960e+02, 8.65000e+00],\n",
       "       [7.75223e+00, 0.00000e+00, 1.81000e+01, 0.00000e+00, 7.13000e-01,\n",
       "        6.30100e+00, 8.37000e+01, 2.78310e+00, 2.40000e+01, 6.66000e+02,\n",
       "        2.02000e+01, 2.72210e+02, 1.62300e+01],\n",
       "       [9.88430e-01, 0.00000e+00, 8.14000e+00, 0.00000e+00, 5.38000e-01,\n",
       "        5.81300e+00, 1.00000e+02, 4.09520e+00, 4.00000e+00, 3.07000e+02,\n",
       "        2.10000e+01, 3.94540e+02, 1.98800e+01],\n",
       "       [1.14320e-01, 0.00000e+00, 8.56000e+00, 0.00000e+00, 5.20000e-01,\n",
       "        6.78100e+00, 7.13000e+01, 2.85610e+00, 5.00000e+00, 3.84000e+02,\n",
       "        2.09000e+01, 3.95580e+02, 7.67000e+00],\n",
       "       [5.69175e+00, 0.00000e+00, 1.81000e+01, 0.00000e+00, 5.83000e-01,\n",
       "        6.11400e+00, 7.98000e+01, 3.54590e+00, 2.40000e+01, 6.66000e+02,\n",
       "        2.02000e+01, 3.92680e+02, 1.49800e+01]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train[:10,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**原因：数据没有标准化，数据大小不一，并且设置的eta值过大，使得求得的梯度非常大，导致算法不收敛，出现overflow报错**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用数据标准化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler\n",
    "sc =StandardScaler()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "sc.fit(X_train)\n",
    "X_train_standard = sc.transform(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg3 = LinearRegression()\n",
    "lin_reg3.fit_gd(X_train_standard,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_test_standard = sc.transform(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8129794246544336"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg3.score(X_test_standard, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 梯度下降法的优势"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "m = 1000\n",
    "n = 5000\n",
    "\n",
    "big_X = np.random.normal(size=(m,n))\n",
    "true_theta = np.random.uniform(0.0,100.0,size=n+1)\n",
    "\n",
    "big_y = big_X.dot(true_theta[1:]) + true_theta[0] + np.random.normal(0.,10.,size=m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 16.4 s, sys: 296 ms, total: 16.7 s\n",
      "Wall time: 4.21 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "big_reg1 = LinearRegression()\n",
    "%time big_reg1.fit_normal(big_X, big_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 39.9 s, sys: 64 ms, total: 40 s\n",
      "Wall time: 10 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "big_reg2 = LinearRegression()\n",
    "%time big_reg2.fit_gd(big_X, big_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
